package com.cvit.cn.service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cvit.cn.bean.ExcelBean;
import com.cvit.cn.bean.VendorsQuotations;
import com.cvit.cn.dao.VendorsQuotationsMapper;
import com.cvit.cn.test.ExcelUtil;

@Service
public class VendorsQuotationsService {
	@Autowired
	VendorsQuotationsMapper vendorsQuotationsMapper;

	/**
	 * 设置SupplierType状态值
	 * */
	public void updataSupplierType(VendorsQuotations vq) {
		// TODO Auto-generated method stub
		vendorsQuotationsMapper.updataSupplierType(vq);
	}

	/**
	 * 根据supplierType查报价类别
	 * 0：未参加报价
       1：报价成功
       2：报价失败
       3：报价中
	 * */
	public List<VendorsQuotations> getSupplierTypeSuccess(String vendorsId, String releaseId,String supplierType) {
		// TODO Auto-generated method stub
		return vendorsQuotationsMapper.getSupplierTypeSuccess(vendorsId,releaseId,supplierType);
	}

	/**
	 * 批量添加
	 * */
	public int addQuotations(VendorsQuotations vendorsQuotations) {
		// TODO Auto-generated method stub
		return vendorsQuotationsMapper.insertSelective(vendorsQuotations);
	}
	/**
	 * 根据订单号查询报价的众多供应商
	 * */
	public List<VendorsQuotations> getReleaseById(String releaseId) {
		// TODO Auto-generated method stub
		return vendorsQuotationsMapper.seleReleaseById(releaseId);
	}

	/**
	 * 供应商状态中的所有批物品
	 * */
	public List<VendorsQuotations> getSupplierTypeRelease(String vendorsId, String supplierType) {
		// TODO Auto-generated method stub
		return vendorsQuotationsMapper.seleSupplierTypeRelease(vendorsId,supplierType);
	}

	/**
	 * 供应商未参加报价的订单
	 * */
	public List<VendorsQuotations> getNoSupplierTypeRelease(String vendorsId) {
		// TODO Auto-generated method stub
		return vendorsQuotationsMapper.seleNoSupplierTypeRelease(vendorsId);
	}
	/**
	 * 供应商未参加报价的并进行中的订单
	 * */
	public List<VendorsQuotations> getNoIngSupplierTypeRelease(String vendorsId) {
		// TODO Auto-generated method stub
		return vendorsQuotationsMapper.seleNoIngSupplierTypeRelease(vendorsId);
	}

	/**
	 * 查询未处理的物品
	 * */
	public List<VendorsQuotations> getSupplierTypeThree(String releaseId) {
		// TODO Auto-generated method stub
		return vendorsQuotationsMapper.getSupplierTypeThree(releaseId);
	}
	/**
	 * 查询处理成功的物品
	 * */
	public List<VendorsQuotations> getSupplierTypeOne(String releaseId) {
		// TODO Auto-generated method stub
		return vendorsQuotationsMapper.getSupplierTypeOne(releaseId);
	}
	/**
	 * 导出Excel
	 * */
	public XSSFWorkbook exportExcelInfo(String VendorsQuotationsData,String vendorsId,String releaseId) throws Exception {  
	    //根据条件查询数据，把数据装载到一个list中  
	    List<VendorsQuotations> list = vendorsQuotationsMapper.getVendorsById(vendorsId,releaseId);
	    List<ExcelBean> excel=new ArrayList<ExcelBean>();
	    Map<Integer,List<ExcelBean>> map=new LinkedHashMap<Integer, List<ExcelBean>>();
	    XSSFWorkbook xssfWorkbook=null;
	    //设置标题栏
	    excel.add(new ExcelBean("公司名","supplierName",0));
	    excel.add(new ExcelBean("制单人","oneId",0));
	    excel.add(new ExcelBean("申请人","twoId",0));
	    excel.add(new ExcelBean("申请部门","department",0));
	    excel.add(new ExcelBean("物品名","commodityName",0));
	    excel.add(new ExcelBean("物品型号","specificationModel",0));
	    excel.add(new ExcelBean("单位","company",0));
	    excel.add(new ExcelBean("数量","number",0));
	    excel.add(new ExcelBean("单价","unitPrice",0));
	    excel.add(new ExcelBean("总价","money",0));
	    excel.add(new ExcelBean("总合计","total",0));
	    excel.add(new ExcelBean("备注","commodityCategory",0));
	    //excel.add(new ExcelBean("备注","remarks",0));
	    map.put(0, excel);
	    String sheetName = VendorsQuotationsData;
	    //调用ExcelUtil的方法
	    xssfWorkbook = ExcelUtil.createExcelFile(VendorsQuotations.class, list, map, sheetName);
	    return xssfWorkbook;
	}
}
